<?include ($_SERVER ["DOCUMENT_ROOT"] . "/lib/module/conn_db.php");?>
<?include ($_SERVER ["DOCUMENT_ROOT"] . "/lib/module/Util.php");?>
<?php //DB Open

	$result = null;
	$db = new MyDB ( false );
	$db->err_report = true;

?>
<?php

	$util = new Util();

	$page = $_GET ["page"];
	$orderby = $_GET ["orderby"];
	
	if (!$orderby) $orderby = "article_title ASC";
	else $orderby .= " ASC";

	if (!$page)	$page = 1;

	$pern = 8;
	$perb = 10;

	$condition = $_GET ["condition"];
	$words = $_GET ["words"];

	if($condition!="" && $words!=""){
		$search .= " and ".$condition." LIKE '%".$words."%'";
	}

	$sid = $_GET['sid'];

	$addStr = "sid=".$sid;

?>

<style>
#han:link {color: red;text-decoration: none;}
#han:visited {text-decoration: none;color: red;}
#han:hover {text-decoration: underline;color: #CCC876;font-weight: bold;}
#han:active {text-decoration: none;color: red;font-weight: bold;}
</style>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<? include "inc/inc_header.php" ?><!-- header -->
 <body style="background-color:transparent" >
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	 <tr>
       <td align="right" class="text08" style="padding-bottom:10px;"><strong>[가나다順]</strong></td>
     </tr>
	  <tr>
		<td align="right" style="padding-bottom:10px;">
		<form name="frm" method="get" action="<?=$pageUrl?>">
		<table width="0" border="0" cellspacing="0" cellpadding="0">
			<tr>
			  <td style="padding-right:4px"> <select name="condition" id="condition"  class="box01">
				  <option value="article_title" <?=$condition=="article_title" ? "selected" : "" ?>>제목</option>
				  <option value="article_contents1" <?=$condition=="article_contents1" ? "selected" : "" ?>>내용</option>
			  </select></td>
			  <td style="padding-right:4px">
			  <input type="hidden" name="sid" value="<?=$sid?>"/>
			  <input type="hidden" name="page" value="<?=$page?>"/>
			  <input type="text" name="words" title="검색어" class="box01" size="35" value="<?=$words?>" /></td>
			  <td><input type="image" src="img/board/btn_search.gif" alt="검색하기" style="width:50px;height:20px;"/></td>
			</tr>
		</table>
		</form>
		</td>
	  </tr>

	  <tr>
		<td><img src="img/bt_left_01.png"></td>
	  </tr>

	  <tr><td height="8"></td></tr>
	  <tr>
		<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td>
<?

	$sql = "SELECT * from tb_board_article WHERE category_sid=".$sid." and board_sid=3".$search." and etc_cate='1' ORDER BY ".$orderby;
	$db->query ( $sql );
	$query = $db->result;
	$total = mysql_num_rows ($query);

//	if ($total > 0) {
//
//		$lastpage = ceil( $total / $pern );
//		if ( $page > $lastpage ) $page = $lastpage;
//		$first = ( $page - 1 ) * $pern;
//
		// 페이징 목록
//		$lastbl = ceil ( $lastpage / $perb );
//		$bl = ceil ( $page / $perb );
//		$stpage = ($bl - 1) * $perb + 1;
//		$edpage = ($bl - 1) * $perb + $perb;
		// 글번호
//		$start_no = $total - (($page - 1) * $pern);
//
//		$sql .= " limit $first, $pern ";
//
//
		$db->query ( $sql );
		$result = $db->result;
//	}
	$i=0;
?>
			  <?php if($total>0):?>
				<?php while($row = mysql_fetch_object($result)):?>
				  <?php if($i%4==0):?>
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
					  <tr>
				  <?php endif;?>
						 <td <?php if($i%4!=3):?>width="248"<?php endif;?> valign="top" style="padding-bottom:30px;"><table width="210" border="0" cellspacing="0" cellpadding="0">
							  <tr>
								<td><a href="surn01_01_2_v.php?sid=<?php echo $sid;?>&art_sid=<?php echo $row->article_sid;?>&page=<?php echo $page;?>">
								<?php
									$sql = "SELECT file_name from tb_board_file WHERE article_sid=".$row->article_sid." ORDER BY file_sid DESC limit 0,1;";
									$db->query ( $sql );
									$file = mysql_fetch_object($db->result);
								?>
									<img src="uploads/3/<?php echo $file->file_name;?>" width="206" height="136" border="0">
								</a></td>
							  </tr>
							  <tr>
								<td align="center" class="text02" style="padding-top:8px;"><strong><?php echo $row->article_title;?></strong></td>
							  </tr>
						  </table></td>
				  <?php if ($i+1==$total) :?>
					<?php $q = $i%4+1;;?>
					<?php for ($j=0; $j<3-($i%4); $j++) :?>
						<td <?php if($q%4!=3):?>width="248"<?php endif;?> class="text02">&nbsp;</td>
						<?php $q++;?>
					<?php endfor;?>
				  <?php endif;?>
				  <?php if($i%4==3 || ($q-1)%4==3):?>
					  </tr>
					</table>
				  <?php endif;?>
				  <?php $i++;?>
				<?php endwhile;?>
			  <?php endif;?>
		</td>
	  </tr>

<!------------------------------------------------------------------------------------------------------------------------------------------------------------------------>
	  <tr><td height="10"></td></tr>
	  <tr>
		<td><img src="img/bt_left_02_2.png"></td>
	  </tr>

	  <tr><td height="8"></td></tr>
	  <tr>
		<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td>
<?

	$sql = "SELECT * from tb_board_article WHERE category_sid=".$sid." and board_sid=3".$search." and (etc_cate='2' or etc_cate='') ORDER BY ".$orderby;
	$db->query ( $sql );
	$query = $db->result;
	$total = mysql_num_rows ($query);

		$db->query ( $sql );
		$result = $db->result;
	$i=0;
	$j=0;
	$q=0;
?>
			  <?php if($total>0):?>
				<?php while($row = mysql_fetch_object($result)):?>
				  <?php if($i%4==0):?>
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
					  <tr>
				  <?php endif;?>
						 <td <?php if($i%4!=3):?>width="248"<?php endif;?> valign="top" style="padding-bottom:30px;"><table width="210" border="0" cellspacing="0" cellpadding="0">
							  <tr>
								<td><a href="surn01_01_2_v.php?sid=<?php echo $sid;?>&art_sid=<?php echo $row->article_sid;?>&page=<?php echo $page;?>">
								<?php
									$sql = "SELECT file_name from tb_board_file WHERE article_sid=".$row->article_sid." ORDER BY file_sid DESC limit 0,1;";
									$db->query ( $sql );
									$file = mysql_fetch_object($db->result);
								?>
									<img src="uploads/3/<?php echo $file->file_name;?>" width="206" height="136" border="0">
								</a></td>
							  </tr>
							  <tr>
								<td align="center" class="text02" style="padding-top:8px;"><strong><?php echo $row->article_title;?></strong></td>
							  </tr>
						  </table></td>
				  <?php if ($i+1==$total) :?>
					<?php $q = $i%4+1;;?>
					<?php for ($j=0; $j<3-($i%4); $j++) :?>
						<td <?php if($q%4!=3):?>width="248"<?php endif;?> class="text02">&nbsp;</td>
						<?php $q++;?>
					<?php endfor;?>
				  <?php endif;?>
				  <?php if($i%4==3 || ($q-1)%4==3):?>
					  </tr>
					</table>
				  <?php endif;?>
				  <?php $i++;?>
				<?php endwhile;?>
			  <?php endif;?>
		</td>
	  </tr>
<!------------------------------------------------------------------------------------------------------------------------------------------------------------------------>


<!------------------------------------------------------------------------------------------------------------------------------------------------------------------------>
	  <tr><td height="10"></td></tr>
	  <tr>
		<td>
			<table border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td><img src="img/bt_left_03_2.png"></td>
				<td valign="bottom">&nbsp;&nbsp;<span style="font-size:14px; color:red;">* 수정할 부분이나 추가 등재를 원하시면(개인 또는 문중) 본회 상담센터(02-403-9884/ 팩스 02-406-7664)로 연락바랍니다.</span></td>
			</tr>
			</table>
		</td>
	  </tr>

	  <tr><td height="8"></td></tr>
	  <tr>
		<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td>
<?

	$sql = "SELECT * from tb_board_article WHERE category_sid=".$sid." and board_sid=3".$search." and etc_cate='3' ORDER BY ".$orderby;
	$db->query ( $sql );
	$query = $db->result;
	$total = mysql_num_rows ($query);

		$db->query ( $sql );
		$result = $db->result;
	$i=0;
	$j=0;
	$q=0;
?>
			  <?php if($total>0):?>
				<?php while($row = mysql_fetch_object($result)):?>
				  <?php if($i%4==0):?>
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
					  <tr>
				  <?php endif;?>
						 <td <?php if($i%4!=3):?>width="248"<?php endif;?> valign="top" style="padding-bottom:30px;"><table width="210" border="0" cellspacing="0" cellpadding="0">
							  <tr>
								<td><a href="surn01_01_2_v.php?sid=<?php echo $sid;?>&art_sid=<?php echo $row->article_sid;?>&page=<?php echo $page;?>">
								<?php
									$sql = "SELECT file_name from tb_board_file WHERE article_sid=".$row->article_sid." ORDER BY file_sid DESC limit 0,1;";
									$db->query ( $sql );
									$file = mysql_fetch_object($db->result);
								?>
									<img src="uploads/3/<?php echo $file->file_name;?>" width="206" height="136" border="0">
								</a></td>
							  </tr>
							  <tr>
								<td align="center" class="text02" style="padding-top:8px;"><strong><?php echo $row->article_title;?></strong></td>
							  </tr>
						  </table></td>
				  <?php if ($i+1==$total) :?>
					<?php $q = $i%4+1;;?>
					<?php for ($j=0; $j<3-($i%4); $j++) :?>
						<td <?php if($q%4!=3):?>width="248"<?php endif;?> class="text02">&nbsp;</td>
						<?php $q++;?>
					<?php endfor;?>
				  <?php endif;?>
				  <?php if($i%4==3 || ($q-1)%4==3):?>
					  </tr>
					</table>
				  <?php endif;?>
				  <?php $i++;?>
				<?php endwhile;?>
			  <?php endif;?>
		</td>
	  </tr>
<!------------------------------------------------------------------------------------------------------------------------------------------------------------------------>

	</table>
 </body>
</html>
<?php //DB Close

	$db->close ();

?>